package com.easydata.agent.core;


import com.easydata.agent.service.DAGService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class TaskPool {
    ConcurrentHashMap<String, Task> taskMap = new ConcurrentHashMap<>();

    @Autowired
    DAGService dagService;

    synchronized public Task getTask(String id) {
        return taskMap.getOrDefault(id, null);
    }

    synchronized public Task removeTask(String id) {
        return taskMap.remove(id);
    }

    synchronized public Task addTask(Task task){
        this.taskMap.put(task.getId(),task);
        return task;
    }

    synchronized public List<Task> getAll(){
        return taskMap.values().stream().toList();
    }
}
